Learn how to deal with errors in transmission.
Checkout the project Lab04 from your svn repository (svn update
should
do the trick if you checked out your entire repository in Lab01). Write
your solutions to the problem below in that folder.
Modify your solution to the previous lab assignment (or the solution we provided)
to handle missing packets during file transfer. Note: Our solution to the
previous lab is committed to your repository in Lab03Solution
.
Here is the new behavior that you can expect from the server:
a) server will always wait for a final ACK
from the client
after sending all packets for a file.
b) server will sometimes fail to send packets when responding
to the GET
command, but it will always send:
-- the fifth packet of any group of five
-- the last packet of the file
-- the final ACK
after finishing sending a file.
c) server will respond to each request for retransmission of
a packet (RETR
command) by sending that packet. It will
then wait for more retransmission requests or an ACK
.
Here is a typical scenario without any lost packets. The numbers are the sequence numbers in the packets:
Client Server
------ ------
GET ----------->
<----------- DATA 0
<----------- DATA 1
<----------- DATA 2
<----------- DATA 3
<----------- DATA 4
ACK 4 ----------->
<----------- DATA 5
<----------- DATA 6
<----------- DATA 7
<----------- ACK 7
ACK 7 ----------->
Note the final ACK
from the client. This ACK
is required to
count the file transfer as successful.
Here is a typical scenario involving retransmission. Note that the client indicates which packet it wants via the sequence number:
Client Server
------ ------
GET ----------->
X----- DATA 0
<----------- DATA 1
X----- DATA 2
<----------- DATA 3
<----------- DATA 4
RETR 0 ----------->
<----------- DATA 0
RETR 2 ----------->
<----------- DATA 2
ACK 4 ----------->
<----------- DATA 5
<----------- DATA 6
<----------- DATA 7
<----------- ACK 7
ACK 7 ----------->
Your client program will now have to buffer the packets it receives from the server before writing them to the file. That way it can make sure that all the bytes are written in the right order.
To enable the new funcionality with the server, use one of the following options:
-d n
will never drop packets.
-d r
will drop packets randomly.
-d 0
will drop the first packet of every collection of
packets (unless that is the last packet for the file).
-d 1
will drop the second packet of every collection of
packets (unless that is the last packet for the file).
-d 2
will drop the third packet of every collection of
packets (unless that is the last packet for the file).
-d 3
will drop the fourth packet of every collection of
packets (unless that is the last packet for the file).
server
also includes a sequence number when it sends its ACK at the
end of a file. The sequence number is the same as the last packet for
the file.
We recommend also using the -x
option for displaying packets sent,
received, and dropped by the server. -v
will display contextual
information, such as when the server starts and stops a file transfer.
The server programs are available in the Lab04/SERVER folder in your repository.
You should start with your solution to Lab03.
Compile and run the programs in the Linux environment.
Use a consistent set of coding standards. The GNU C coding standards are available at http://www.gnu.org/prep/standards/standards.html#Writing-C Sections to look at are "Comments", "Formatting", "Syntatic Conventions", and "Names".
Submit the source files (.c), the header files (.h) and the Makefile to your svn repository.
An example program called arrayofstruct.c
is provided in your
repository. It demonstrates how to create an array of structures and how to
access and assign values to the array items.
While it is convenient for the server to not drop certain packets, in the real world it is not safe to assume that certain packets will be transmitted successfully. Furthermore, it is not safe to assume that all packets arrive at their destination without changing.
For this potential extra credit opportunity, explore these scenarios by
modifying your solution to handle the server dropping the 5th packet in a
transmission (use the -d 4
server option). Note that this may also cause the
server to drop the final packet in a file, but the server will always send the
final ACK
packet. The server also supports a -c
option that functions in
the same way as the -d
option, except the server will instead corrupt the packet
that it sends to the client. Your client should handle these packet drops and
corruptions by requesting those packets for retransmission.
The following code can be used to generate a sum for a packet:
int sumPacket(const PACKET* packet)
{
int sum = packet->control;
sum += packet->sequence;
sum += packet->loadsize;
int i;
for (i = 0; i < LOADSIZE/sizeof(int); i += sizeof(int))
sum += ntohl(((const int*)packet->data)[i]);
return sum;
}